package inet.app.vod.adapter;

import inet.app.vod.object.MovieModel;
import inet.app.vod.view.VideoSummaryView;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.inet.app.framework.bitmap.UniversalImageUtil;

public class VideoSummaryAdapter extends ArrayAdapter<MovieModel> {

	List<MovieModel> mMovieModels;
	Context mContext;

	public VideoSummaryAdapter(Context context, int textViewResourceId,
			List<MovieModel> objects, boolean isCustomSize) {

		super(context, textViewResourceId, objects);
		this.mContext = context;
		this.mMovieModels = objects;
	}

	@Override
	public int getCount() {
		return mMovieModels.size();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;

		final MovieModel model = mMovieModels.get(position);
		
		if (convertView == null) {
			convertView = new VideoSummaryView(mContext);

			holder = new ViewHolder();
			holder.mainLayout = ((VideoSummaryView) convertView).mMainLayout;
			holder.backGroundView = ((VideoSummaryView) convertView).mBackGround;
			holder.titleTextView = ((VideoSummaryView) convertView).mTitleTextView;
			holder.numView = ((VideoSummaryView) convertView).mNumView;

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.titleTextView.setText(model.getTitle());
		holder.numView.setText(String.valueOf(model.getNumView()));
		UniversalImageUtil.getInstance(mContext).displayImage(model.getImg(),
				holder.backGroundView);

		// convertView.setOnClickListener(new View.OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// // TODO Auto-generated method stub
		// if (mVideoSumListener != null) {
		// mVideoSumListener.onClick(model);
		// }
		// }
		// });

		return convertView;
	}

	static class ViewHolder {
		public RelativeLayout mainLayout;
		public ImageView backGroundView;
		public TextView titleTextView;
		public TextView numView;
	}

}
